//初始化数据库
const db = wx.cloud.database();
// 获取全局app对象
const app = getApp()
import Toast from '@vant/weapp/toast/toast'
Page({
  data: {
    tabs:0,
    order:[],
    price:[]
  },
  onShow(){
let pages = getCurrentPages();
let currentPage=pages[pages.length-1];
    console.log(currentPage.options._id)
    },
  
  async onShow(options) {
    Toast.loading({
      duration: 0,
      message: '加载中...'
    });
    // 检查用户登录
    const flag = await app.loginLogic(this)
    if (flag === 1) {
      console.log(app.globalData.openId)
      this.setData({
      userInfo: app.globalData.userInfo
      });
    
    }
    
  },
  onLoad: function () {
   let that =this
   db.collection('orders').where({
     openId: app.globalData.openId
   }).get({
     success:function(res){
       console.log('数据获取成功',res)
       that.setData({
         order:res.data
       })
        console.log(that.data)
     },fail:function(res){
       console.log('数据获取失败',res)
     }
   })
   
  },
  async getUserInfo(e) { // 不要忘了，按钮去获取用户信息登录
    const flag = await app.getUserInfo(e, this)
    if (flag === 1) {
      this.setData({
        userInfo: app.globalData.userInfo
      })
    }
  },
  onChange(event) {
    wx.showToast({
      title: `${event.detail.title}`,
      icon: 'none'
    });
  }
})